package com.ruoyi.web.controller.user;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.user.domain.Problem;
import com.ruoyi.user.service.IProblemService;

/**
 * 问题反馈 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-12-23
 */
@Controller
@RequestMapping("/problem")
public class ProblemController extends BaseController
{
    private String prefix = "problem";
	
	@Autowired
	private IProblemService problemService;
	
	@RequiresPermissions("problem:view")
	@GetMapping()
	public String problem()
	{
	    return prefix + "/problem";
	}
	
	/**
	 * 查询问题反馈列表
	 */
	@RequiresPermissions("problem:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Problem problem)
	{
		startPage();
        List<Problem> list = problemService.selectProblemList(problem);
		return getDataTable(list);
	}
	
	/**
	 * 新增问题反馈
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存问题反馈
	 */
	@RequiresPermissions("problem:add")
	@Log(title = "问题反馈", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Problem problem)
	{		
		return toAjax(problemService.insertProblem(problem));
	}

	/**
	 * 修改问题反馈
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Problem problem = problemService.selectProblemById(id);
		mmap.put("problem", problem);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存问题反馈
	 */
	@RequiresPermissions("problem:edit")
	@Log(title = "问题反馈", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Problem problem)
	{		
		return toAjax(problemService.updateProblem(problem));
	}
	
	/**
	 * 删除问题反馈
	 */
	@RequiresPermissions("problem:remove")
	@Log(title = "问题反馈", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(problemService.deleteProblemByIds(ids));
	}
	
}
